package com.riant.dayo2.demo5;
import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

/**
 * @Classname Test2
 * @Description TODO
 * @Date 2021/2/27 23:34
 * @Created by 张斌
 */
public class Test2 {
    public static void main(String[] args) throws IllegalAccessException, InstantiationException, NoSuchMethodException, NoSuchFieldException, InvocationTargetException {
        Class cls=User.class;
        User user= (User) cls.newInstance();
        System.out.println(cls.getModifiers());//1
        Method method=cls.getMethod("getName");
        System.out.println(method.getModifiers());//1
        Field field=cls.getDeclaredField("name");
        System.out.println(field.getModifiers());//2
        Constructor constructor = cls.getDeclaredConstructor();
        System.out.println(constructor.getModifiers());//1
        Method method1=cls.getDeclaredMethod("setDepartment",int.class);
        method1.invoke(null,11);//调用静态方法
    }
}
